package cn.findviewbydream.evil.app.controller

import cn.findviewbydream.evil.app.dto.MealBean
import cn.findviewbydream.evil.app.service.MenuService
import cn.findviewbydream.evil.main.entity.BaseMealTypeEntity
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.web.bind.annotation.RequestMapping
import org.springframework.web.bind.annotation.RequestMethod
import org.springframework.web.bind.annotation.RestController


/********************************************
 * 工程名：MealOrder
 * 包名：cn.findviewbydream.evil.app.controller
 * 时间：16-12-28
 * 作者：白雨濃 evil
 * 邮箱：evilbai@foxmail.com
 * 内容：菜单Controller
 ********************************************/
@RestController
class MenuController(@Autowired val menuService: MenuService)
{
    @RequestMapping("/app/get/meal/type/list")
    fun getBaseMealTypeList(): List<BaseMealTypeEntity>? = menuService.getBaseMealTypeList()

    @RequestMapping("/app/get/meal/list")
    fun getMealList(): List<MealBean>? = menuService.getMealList()

    /**
     * 新订单提交
     */
    @RequestMapping("/app/post/order", method = arrayOf(RequestMethod.POST))
    fun postOrder(json: String): String?
    {
        try
        {
            return menuService.setOrder(json).toString()
        }
        catch (e: Exception)
        {
            return e.message
        }
    }

    /**
     * 老订单提交修改-> 订单update 订单项目insert
     */
    @RequestMapping("/app/post/order/update", method = arrayOf(RequestMethod.POST))
    fun postOrderUpdate(json: String): String?
    {
        try
        {
            return menuService.setOrderUpdate(json).toString()
        }
        catch (e: Exception)
        {
            return e.message
        }
    }
}